/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.sipper.ksip.scores;


import org.jgrapht.DirectedGraph;
import org.jgrapht.graph.DefaultWeightedEdge;


import combi.wip.sipper.ksip.KSip;


public class NeighbouringCoefficient implements ScoreKSIP{

	private double defaultScore;
	//double defaulscore;

	public NeighbouringCoefficient(double defaultScore)
	{
		this.defaultScore = defaultScore;
	}

	@Override
	public double getScore(KSip paths) {
		//
		DirectedGraph<Integer, DefaultWeightedEdge> subgraph = paths.toSubGraph();
		double weight = 0;
		for (DefaultWeightedEdge e : subgraph.edgeSet())
		{
			weight += subgraph.getEdgeWeight(e);
		}
		return (weight/(double)paths.getReactions().size());
	}

	@Override
	public double getWorst() {
		return defaultScore;
	}

	@Override
	public int best(double first, double second) {
		return (first<=second)? -1:1;
	}

}
